<?php
class ModelAffiliateTransaction extends Model {
	public function getTransactions($start, $limit = 10) {
		$sql = "SELECT * FROM `@@affiliate_transaction` WHERE affiliate_id = " . (int)$this->affiliate->getId();
		$sql .= " ORDER BY date_added DESC";
		$sql .= " LIMIT $start, $limit";
		$query = $this->db->query($sql);
		
		return $query->rows;
	}

	public function getTotalTransactions() {
      	return $this->db->queryOne("SELECT COUNT(*) AS total FROM `@@affiliate_transaction` WHERE affiliate_id = " . (int)$this->affiliate->getId());
	}

	public function getBalance() {
		$query = $this->db->query("SELECT SUM(amount) AS total FROM `@@affiliate_transaction` WHERE affiliate_id = " . (int)$this->affiliate->getId() . " GROUP BY affiliate_id");

		if ($query->num_rows) {
			return $query->row['total'];
		} else {
			return 0;
		}
	}
}
?>